#include <stdio.h>
#include <unistd.h>
#include "mpi.h"

int
main(int argc, char **argv)
{
	int size, rank, count, a[2], b[3];
	MPI_Status status;
	int success = 1;
	
	MPI_Init(&argc, &argv);
	
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);

	a[0] = 42;
	a[1] = 420;

	if (rank == 0)
	{
		MPI_Send(a, 2, MPI_INT, 1, 0, MPI_COMM_WORLD);
		MPI_Send(a, 2, MPI_BYTE, 1, 0, MPI_COMM_WORLD);
	}
	else 
	{
		MPI_Recv(b, 2, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
		MPI_Get_count(&status, MPI_INT, &count);
		printf("count=%d\n", count);
		success = success && (count == 2);
		MPI_Recv(b, 3, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
		MPI_Get_count(&status, MPI_INT, &count);
		printf("count=%d\n", count);
		success = success && (count == MPI_UNDEFINED);

		if (success == 1) {
			printf("SUCCESS\n");
		}
		else
		{
			printf("FAILURE\n");
		}
	}
	
	
	MPI_Finalize();
	return 0;
}

